package com.hkf.shop.controller;

import com.hkf.shop.service.UserService;
import com.yyds.shop.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor;

import java.util.List;

/**
 * @author huangkf
 * @version 1.0
 * @date 2022/12/16:10:44
 * @description 用户控制层
 */


@RestController
@RequestMapping("user")
public class UserController {


    @Autowired
    private UserService userService;

    //获取所有用户
    @GetMapping("getAll")
    public List<User> findUsers() {

        List<User> allUser = userService.findAllUser();

        return allUser;

    }

    //根据id获取用户
    @GetMapping("getUserById/{id}")
    public User findById(@PathVariable (value = "id")  String id) {
        User byId = userService.findById(id);
        return byId;
    }


    //添加用户
    @PostMapping("addUser")
    public String  addUser(User user) {
        String result = "";
        boolean b = userService.addUser(user);
        if (b == true) {
            result= "插入成功";
        } else {
            result = "插入失败";
        }

        return result;
    }
 }
